﻿
using IDAdmin.Common;
using IDAdmin.Lib.DataLayer;
using IDAdmin.Lib.UI;
using IDAdmin.Lib.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IDAdmin.Pages
{
    public partial class LoginNewSaveStatistics : BasePage
    {
        public LoginNewSaveStatistics()
            : base(Lib.AppFunctions.LOGINNEWSAVE)
        { }
        protected override void Page_Load(object sender, EventArgs e)
        {
            if (!IsLogin())
            {
                RedirectToLogOn();
            }
            else if (!CheckRight())
            {
                RedirectToDeniedMessage();
            }
        }

        protected void countButton_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            dataPanel.Controls.Clear();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            dataPanel.Controls.Add(getLoginNewSave(WebDB.getAu(dateTimeList), WebDB.getCcu(dateTimeList)));
            watch.Stop();
            double elapsedMS = watch.ElapsedMilliseconds;
            measureLB.Text = elapsedMS.ToString() + "miliseconds";
        }
        public static void cronLoginNewSaveFromDateToDate(List<DateTime> dateTimeList)
        {
            List<LoginNewSave> loginNewSaveList = new List<LoginNewSave>();
            LoginNewSaveWebDB lnsWebDB = new LoginNewSaveWebDB();
            foreach (DateTime date in dateTimeList)
            {
                LoginNewSave lns = new LoginNewSave();

                //DateTime date = DataToolUtil.convertStringToDateTime(txtCountDate.Text);
                lns.Nau = lnsWebDB.getNau(date).ToString();

                string out1 = "";
                string out2 = "";
                lnsWebDB.getDaySecondSave(date, out out1, out out2);
                lns.DaySecondSave = out1;
                lns.PercentDaySecondSave = out2;

                string out3 = "";
                string out4 = "";
                lnsWebDB.getDayThirdSave(date, out out3, out out4);
                lns.DayThirdSave = out3;
                lns.PercentDayThirdSave = out4;

                string out5 = "";
                string out6 = "";
                lnsWebDB.getDaySevenSave(date, out out5, out out6);
                lns.DaySevenSave = out5;
                lns.PercentDaySevenSave = out6;

                string out7 = "";
                string out8 = "";
                lnsWebDB.getDayFourTeenDaySave(date, out out7, out out8);
                lns.DayFourteenSave = out7;
                lns.PercentDayFourteenSave = out8;

                string out9 = "";
                string out10 = "";
                lnsWebDB.getDayThirtyDaySave(date, out out9, out out10);
                lns.DayThirtySave = out9;
                lns.PercentDayThirtySave = out10;

                lns.Date = date.ToString("dd/MM/yyyy");
                lns.DateTime = date;
                lns.Ticks = date.Ticks;
                loginNewSaveList.Add(lns);
            }
            lnsWebDB.insertLoginNewSave(loginNewSaveList, dateTimeList);
        }

        public static void cronLoginNewSave(DateTime date)
        {
            List<LoginNewSave> loginNewSaveList = new List<LoginNewSave>();
            LoginNewSaveWebDB lnsWebDB = new LoginNewSaveWebDB();
            LoginNewSave lns = new LoginNewSave();
            List<DateTime> dateTimeList = new List<DateTime>();
            dateTimeList.Add(date);

            //DateTime date = DataToolUtil.convertStringToDateTime(txtCountDate.Text);
            lns.Nau = lnsWebDB.getNau(date).ToString();

            string out1 = "";
            string out2 = "";
            lnsWebDB.getDaySecondSave(date, out out1, out out2);
            lns.DaySecondSave = out1;
            lns.PercentDaySecondSave = out2;

            string out3 = "";
            string out4 = "";
            lnsWebDB.getDayThirdSave(date, out out3, out out4);
            lns.DayThirdSave = out3;
            lns.PercentDayThirdSave = out4;

            string out5 = "";
            string out6 = "";
            lnsWebDB.getDaySevenSave(date, out out5, out out6);
            lns.DaySevenSave = out5;
            lns.PercentDaySevenSave = out6;

            string out7 = "";
            string out8 = "";
            lnsWebDB.getDayFourTeenDaySave(date, out out7, out out8);
            lns.DayFourteenSave = out7;
            lns.PercentDayFourteenSave = out8;

            string out9 = "";
            string out10 = "";
            lnsWebDB.getDayThirtyDaySave(date, out out9, out out10);
            lns.DayThirtySave = out9;
            lns.PercentDayThirtySave = out10;

            lns.Date = date.ToString("dd/MM/yyyy");
            lns.DateTime = date;
            lns.Ticks = date.Ticks;
            loginNewSaveList.Add(lns);
            lnsWebDB.insertLoginNewSave(loginNewSaveList, dateTimeList);
        }
        private Table getLoginNewSaveTable()
        {
            List<LoginNewSave> loginNewSaveList = new List<LoginNewSave>();
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            dateTimeList = dateTimeList.OrderByDescending(o =>o).ToList();
            LoginNewSaveWebDB lnsWebDB = new LoginNewSaveWebDB();
            foreach (DateTime date in dateTimeList)
            {
                LoginNewSave lns = new LoginNewSave();
               
                //DateTime date = DataToolUtil.convertStringToDateTime(txtCountDate.Text);
                lns.Nau = lnsWebDB.getNau(date).ToString();

                string out1 = "";
                string out2 = "";
                lnsWebDB.getDaySecondSave(date, out out1, out out2);
                lns.DaySecondSave = out1;
                lns.PercentDaySecondSave = out2;

                string out3 = "";
                string out4 = "";
                lnsWebDB.getDayThirdSave(date, out out3, out out4);
                lns.DayThirdSave = out3;
                lns.PercentDayThirdSave = out4;

                string out5 = "";
                string out6 = "";
                lnsWebDB.getDaySevenSave(date, out out5, out out6);
                lns.DaySevenSave = out5;
                lns.PercentDaySevenSave = out6;

                string out7 = "";
                string out8 = "";
                lnsWebDB.getDayFourTeenDaySave(date, out out7, out out8);
                lns.DayFourteenSave = out7;
                lns.PercentDayFourteenSave = out8;

                string out9 = "";
                string out10 = "";
                lnsWebDB.getDayThirtyDaySave(date, out out9, out out10);
                lns.DayThirtySave = out9;
                lns.PercentDayThirtySave = out10;

                lns.Date = date.ToString("dd/MM/yyyy");
                lns.DateTime = date;
                lns.Ticks = date.Ticks;
                loginNewSaveList.Add(lns);
            }
            loginNewSaveList = loginNewSaveList.OrderByDescending(o => o.Ticks).ToList();
            lnsWebDB.insertLoginNewSave(loginNewSaveList,dateTimeList);

            Table table = new Table();
            table.CssClass = "table1";
            table.CellSpacing = 1;
            TableRow rowHeader = new TableRow();
            rowHeader.Cells.AddRange
            (
                new TableCell[]
                {     
                    UIHelpers.CreateTableCell("STT",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Thời gian",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Nau",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Ngày thứ 2 lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Cách 1 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("7 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("14 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("30 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                      UIHelpers.CreateTableCell("Ngày thứ 2 lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Cách 1 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("7 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("14 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("30 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                }
            );

            table.Rows.Add(rowHeader);
            try
            {
                if (loginNewSaveList == null || loginNewSaveList.Count == 0)
                {
                    TableRow rowEmpty = new TableRow();
                    rowEmpty.Cells.Add(UIHelpers.CreateTableCell("<p>Không có dữ liệu!</p>", HorizontalAlign.Center, "cell1", 4));
                    table.Rows.Add(rowEmpty);
                }
                else
                {
                    //labelCountOfUser.Text = string.Format("{0:N0}", dt.Rows.Count);
                    string css;
                    int stt = 0;
                    foreach (var dr in loginNewSaveList)
                    {
                        stt += 1;
                        css = stt % 2 == 0 ? "cell1" : "cell2";
                        TableRow row = new TableRow();
                        row.Cells.AddRange
                        (
                            new TableCell[]
                           {
                                    UIHelpers.CreateTableCell(stt.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.Date),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.Nau),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DaySecondSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayThirdSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DaySevenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayFourteenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayThirtySave),HorizontalAlign.Center,css),
                                     UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDaySecondSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayThirdSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDaySevenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayFourteenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayThirtySave),HorizontalAlign.Center,css)
                           }
                        );

                        table.Rows.Add(row);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return table;
        }
        private Table getLoginNewSave(List<Au> auData, List<Ccu> ccuData)
        {
            List<Au> auList = new List<Au>(auData.Count);

            auData.ForEach((item) =>
            {
                auList.Add(new Au(item));
            });

            List<Ccu> ccuList = new List<Ccu>(ccuData.Count);

            ccuData.ForEach((item) =>
            {
                ccuList.Add(new Ccu(item));
            });

            foreach (Au auItem in auList)
            {
                auItem.Timestamp = ConverterWorkData.truncateTime(auItem.Timestamp, "dd/MM/yyyy");
            }
            foreach (Ccu ccuItem in ccuList)
            {
                ccuItem.Timestamp = ConverterWorkData.truncateTime(ccuItem.Timestamp, "dd/MM/yyyy");
            }

            #region timeList
            //var timeList = ((from tb1 in ccuList select tb1.Timestamp).Union(from tb2 in auList select tb2.Timestamp)).Distinct().ToList();
            //timeList.Sort();
            List<string> timeList = new List<string>();
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            foreach (DateTime item in dateTimeList)
            {
                string timestamp = ConverterWorkData.truncateTime(ConverterWorkData.kindDateTimeToKindUnixTimestamp(item, DateTimeKind.Local).ToString(), "dd/MM/yyyy");
                timeList.Add(timestamp);
            }
            timeList = timeList.OrderByDescending(o => o).ToList();
            #endregion
            List<LoginNewSave> loginNewSaveList = new List<LoginNewSave>();

            for (int i = 0; i < timeList.Count; i++)
            {

                LoginNewSave lns = new LoginNewSave();
                var nau = "";

                var accountBeforeAtTimeList = (from tb in auList.AsParallel() where long.Parse(tb.Timestamp) < long.Parse(timeList[i]) select new { tb.Account }).Distinct().ToList();

                List<string> nauList = new List<string>();
                var accountAtTimeList = (from tb in auList.AsParallel() where tb.Timestamp.Equals(timeList[i]) select new { tb.Account }).Distinct().ToList();

                if (accountBeforeAtTimeList.Count() != 0)
                {
                    foreach (var item in accountAtTimeList)
                    {
                        int numLoop = 0;
                        for (int k = 0; k < accountBeforeAtTimeList.Count(); k++)
                        {
                            if (item.Account.Equals(accountBeforeAtTimeList[k].Account))
                            {
                                break;
                            }
                            else
                            {
                                numLoop++;
                            }

                        }
                        if (numLoop == accountBeforeAtTimeList.Count())
                        {
                            nauList.Add(item.Account);
                        }
                    }

                }
                else
                    if (accountBeforeAtTimeList.Count() == 0)
                    {
                        foreach (var itemTemp in accountAtTimeList)
                        {
                            nauList.Add(itemTemp.Account);
                        }
                    }

                //try
                //{


                nau = nauList.Distinct().Count().ToString();

                // }
                //catch (Exception ex)
                //{
                // nau = "";
                //}

                lns.Nau = nau;

                lns.DateTime = ConverterWorkData.kindUnixTimeStampToKindDateTime(long.Parse(timeList[i]), DateTimeKind.Local, DateTimeKind.Local);
                lns.Date = ConverterWorkData.kindUnixTimeStampToKindDateTime(long.Parse(timeList[i]), DateTimeKind.Local, DateTimeKind.Local).ToString("dd/MM/yyyy");
                lns.TimeStamp = long.Parse(timeList[i]);
                if (int.Parse(nau) != 0)
                {
                    DateTime secondDay = lns.DateTime.AddDays(1);
                    string secondDayTimeStamp = ConverterWorkData.truncateTime(ConverterWorkData.kindDateTimeToKindUnixTimestamp(secondDay, DateTimeKind.Local).ToString(), "dd/MM/yyyy");
                    var check = (from tb in timeList.AsParallel() where tb.Equals(secondDayTimeStamp) select new { tb }).Count();

                    if (check > 0)
                    {
                        int num = 0;
                        foreach (var account in nauList)
                        {
                            var count = (from tb in auList.AsParallel() where tb.Account.Equals(account) && tb.Timestamp.Equals(secondDayTimeStamp) select new { tb.Account }).Count();
                            if (count > 0)
                            {
                                num++;
                            }
                        }
                        lns.DaySecondSave = num.ToString();
                        lns.PercentDaySecondSave = ((num * 100 / int.Parse(nau))) + "%";
                    }

                    DateTime thirdDay = lns.DateTime.AddDays(2);
                    string thirdDayTimeStamp = ConverterWorkData.truncateTime(ConverterWorkData.kindDateTimeToKindUnixTimestamp(thirdDay, DateTimeKind.Local).ToString(), "dd/MM/yyyy");
                    check = (from tb in timeList.AsParallel() where tb.Equals(thirdDayTimeStamp) select new { tb }).Count();
                    if (check > 0)
                    {
                        int num = 0;
                        foreach (var account in nauList)
                        {
                            var count = (from tb in auList.AsParallel() where tb.Account.Equals(account) && tb.Timestamp.Equals(thirdDayTimeStamp) select new { tb.Account }).Count();
                            if (count > 0)
                            {
                                num++;
                            }
                        }
                        lns.DayThirdSave = num.ToString();
                        lns.PercentDayThirdSave = ((num * 100 / int.Parse(lns.Nau))) + "%";
                    }
                    DateTime sevenDay = lns.DateTime.AddDays(7);
                    string sevenDayTimeStamp = ConverterWorkData.truncateTime(ConverterWorkData.kindDateTimeToKindUnixTimestamp(sevenDay, DateTimeKind.Local).ToString(), "dd/MM/yyyy");
                    check = (from tb in timeList.AsParallel() where tb.Equals(sevenDayTimeStamp) select new { tb }).Count();
                    if (check > 0)
                    {
                        int num = 0;
                        foreach (var account in nauList)
                        {
                            var count = (from tb in auList.AsParallel() where tb.Account.Equals(account) && tb.Timestamp.Equals(sevenDayTimeStamp) select new { tb.Account }).Count();
                            if (count > 0)
                            {
                                num++;
                            }
                        }
                        lns.DaySevenSave = num.ToString();
                        lns.PercentDaySevenSave = ((num * 100 / int.Parse(lns.Nau))).ToString() + "%";
                    }
                    DateTime fourTeenDay = lns.DateTime.AddDays(14);
                    string fourTeenDayTimeStamp = ConverterWorkData.truncateTime(ConverterWorkData.kindDateTimeToKindUnixTimestamp(fourTeenDay, DateTimeKind.Local).ToString(), "dd/MM/yyyy");
                    check = (from tb in timeList.AsParallel() where tb.Equals(fourTeenDayTimeStamp) select new { tb }).Count();
                    if (check > 0)
                    {
                        int num = 0;
                        foreach (var account in nauList)
                        {
                            var count = (from tb in auList.AsParallel() where tb.Account.Equals(account) && tb.Timestamp.Equals(fourTeenDayTimeStamp) select new { tb.Account }).Count();
                            if (count > 0)
                            {
                                num++;
                            }
                        }
                        lns.DayFourteenSave = num.ToString();
                        lns.PercentDayFourteenSave = ((num * 100 / int.Parse(lns.Nau))) + "%";
                    }
                    DateTime thirtyDay = lns.DateTime.AddDays(30);
                    string thirtyDayTimeStamp = ConverterWorkData.truncateTime(ConverterWorkData.kindDateTimeToKindUnixTimestamp(thirtyDay, DateTimeKind.Local).ToString(), "dd/MM/yyyy");
                    check = (from tb in timeList.AsParallel() where tb.Equals(thirtyDayTimeStamp) select new { tb }).Count();
                    if (check > 0)
                    {
                        int num = 0;
                        foreach (var account in nauList)
                        {
                            var count = (from tb in auList.AsParallel() where tb.Account.Equals(account) && tb.Timestamp.Equals(thirtyDayTimeStamp) select new { tb.Account }).Count();
                            if (count > 0)
                            {
                                num++;
                            }
                        }
                        lns.DayThirtySave = num.ToString();
                        lns.PercentDayThirtySave = ((num * 100 / int.Parse(lns.Nau))) + "%";
                    }
                }
                loginNewSaveList.Add(lns);
            }
            //string startTime = timeList[0];

            //DataTable dt = ConverterWorkData.ToDataTable(loginNewSaveList, 3, 0);

            Table table = new Table();
            table.CssClass = "table1";
            table.CellSpacing = 1;
            TableRow rowHeader = new TableRow();
            rowHeader.Cells.AddRange
            (
                new TableCell[]
                {     
                    UIHelpers.CreateTableCell("STT",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Thời gian",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Nau",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Ngày thứ 2 lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Cách 1 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("7 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("14 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("30 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                      UIHelpers.CreateTableCell("Ngày thứ 2 lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Cách 1 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("7 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("14 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("30 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                }
            );

            table.Rows.Add(rowHeader);
            try
            {
                if (loginNewSaveList == null || loginNewSaveList.Count == 0)
                {
                    TableRow rowEmpty = new TableRow();
                    rowEmpty.Cells.Add(UIHelpers.CreateTableCell("<p>Không có dữ liệu!</p>", HorizontalAlign.Center, "cell1", 4));
                    table.Rows.Add(rowEmpty);
                }
                else
                {
                    //labelCountOfUser.Text = string.Format("{0:N0}", dt.Rows.Count);
                    string css;
                    int stt = 0;
                    foreach (var dr in loginNewSaveList)
                    {
                        stt += 1;
                        css = stt % 2 == 0 ? "cell1" : "cell2";
                        TableRow row = new TableRow();
                        row.Cells.AddRange
                        (
                            new TableCell[]
                           {
                                    UIHelpers.CreateTableCell(stt.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.Date),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.Nau),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DaySecondSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayThirdSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DaySevenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayFourteenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayThirtySave),HorizontalAlign.Center,css),
                                     UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDaySecondSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayThirdSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDaySevenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayFourteenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayThirtySave),HorizontalAlign.Center,css)
                           }
                        );

                        table.Rows.Add(row);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return table;
        }


        protected void buttonCountSaveLNS_Click(object sender, EventArgs e)
        {
            dataPanel.Controls.Clear();
            dataPanel.Controls.Add(getLoginNewSaveTable());
        }

        private Table getFastLoginNewSave()
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(countToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            LoginNewSaveWebDB lnsWebDB = new LoginNewSaveWebDB();
            List<LoginNewSave> loginNewSaveList = new List<LoginNewSave>();
            loginNewSaveList = lnsWebDB.getLoginNewSaveData(dtFormDate.ToString("yyyy-MM-dd" + " 00:00:00"), dtToDate.ToString("yyyy-MM-dd" + " 23:59:59")).OrderByDescending(o => o.Date).ToList();
            loginNewSaveList = loginNewSaveList.OrderByDescending(o => o.Ticks).ToList();

            Table table = new Table();
            table.CssClass = "table1";
            table.CellSpacing = 1;
            TableRow rowHeader = new TableRow();
            rowHeader.Cells.AddRange
            (
                new TableCell[]
                {     
                    UIHelpers.CreateTableCell("STT",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Thời gian",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Nau",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Ngày thứ 2 lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Cách 1 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("7 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("14 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("30 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                      UIHelpers.CreateTableCell("Ngày thứ 2 lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Cách 1 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("7 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("14 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("30 ngày lưu lại",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader")
                }
            );

            table.Rows.Add(rowHeader);
            try
            {
                if (loginNewSaveList == null || loginNewSaveList.Count == 0)
                {
                    TableRow rowEmpty = new TableRow();
                    rowEmpty.Cells.Add(UIHelpers.CreateTableCell("<p>Không có dữ liệu!</p>", HorizontalAlign.Center, "cell1", 4));
                    table.Rows.Add(rowEmpty);
                }
                else
                {
                    //labelCountOfUser.Text = string.Format("{0:N0}", dt.Rows.Count);
                    string css;
                    int stt = 0;
                    foreach (var dr in loginNewSaveList)
                    {
                        stt += 1;
                        css = stt % 2 == 0 ? "cell1" : "cell2";
                        TableRow row = new TableRow();
                        row.Cells.AddRange
                        (
                            new TableCell[]
                           {
                                    UIHelpers.CreateTableCell(stt.ToString(),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.Date),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.Nau),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DaySecondSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayThirdSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DaySevenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayFourteenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.DayThirtySave),HorizontalAlign.Center,css),
                                     UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDaySecondSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayThirdSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDaySevenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayFourteenSave),HorizontalAlign.Center,css),
                                    UIHelpers.CreateTableCell(Converter.ToString(dr.PercentDayThirtySave),HorizontalAlign.Center,css)
                           }
                        );

                        table.Rows.Add(row);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return table;
        }
        protected void buttonCountLNS_Click(object sender, EventArgs e)
        {
            dataPanel.Controls.Clear();
            dataPanel.Controls.Add(getFastLoginNewSave());
        }

    }
}